<?php

namespace System;

/**
 * Description of Session
 *
 * @author nofear
 */
class Session {

    public static $_instance;
    private $Session;

    private function __construct() {
        $this->Session = &$_SESSION;
    }

    public function __call($name, $arguments) {
        if ( substr($name, 0, strlen('get')) == 'get' ) {
            $name = lcfirst(substr($name, strlen('get')));
            
            if ( isset($this->Session[$name]) ) {
                return $this->Session[$name];
            }
        } else if ( substr($name, 0, strlen('set')) == 'set' ) {
            $name = lcfirst(substr($name, strlen('set')));
            
            if ( isset($arguments[0]) ) {
                $this->Session[$name] = $arguments[0];
                
                return true;
            }
        } else if ( substr($name, 0, strlen('remove')) == 'remove' ) {
            $name = lcfirst(substr($name, strlen('remove')));
            
            if ( isset($this->Session[$name]) ) {
                unset($this->Session[$name]);
                
                return true;
            }
        }
        
        return false;
    }

    public function have($name) {
        return isset($this->Session[$name]);
    }
    
    public function getSession() {
        return $this->Session;
    }

    public function setSession($Session) {
        $this->Session = $Session;
    }

    public static function getInstance() {
        if (!self::$_instance) {
            self::$_instance = new self;
        }

        return self::$_instance;
    }

}
